import CryptoJS from 'crypto-js';

const crpytoConfig = {
  API_KEY:  CryptoJS.enc.Utf8.parse('SDWAN-ENCRYPTPWD')
};

/**
 * @description aes解密 Base64 （后端对接用）
 * @param {string} word 需要解密的字符串
 */

export const cryptoDecryptBase = word => {
  if (!word) return '';
  
  const { API_KEY } = crpytoConfig;

  let ciphertext = CryptoJS.enc.Base64.parse(word);

  let decrypted = CryptoJS.AES.decrypt(
    { ciphertext: ciphertext },
    API_KEY,
    { mode: CryptoJS.mode.ECB }
  );

  let decryptedText = CryptoJS.enc.Utf8.stringify(decrypted);

  return decryptedText;
}
